package com.dayaokeji.rhythmschoolstudent.client.common;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.ApiConstantKt;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.BaseActivity;
import com.dayaokeji.rhythmschoolstudent.glide.GlideUrlModel;
import com.dayaokeji.rhythmschoolstudent.glide.GlideUtils;
import com.dayaokeji.rhythmschoolstudent.utils.PrefUtils;
import com.dayaokeji.rhythmschoolstudent.utils.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;

public class ShowBigImageActivity extends BaseActivity {

    private static final String EXTRA_IMG_PATH = "img_path";

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.iv_show_img)
    PhotoView ivShowImg;
    private int imgId;


    public static void navigation(Context context,Integer imgId) {
        Intent intent = new Intent(context, ShowBigImageActivity.class);
        intent.putExtra(EXTRA_IMG_PATH,imgId);
        context.startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().getDecorView().setBackgroundColor(Color.BLACK);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_course_task_image);
        setSupportActionBar(toolbar);
        imgId = getIntent().getIntExtra(EXTRA_IMG_PATH, -1);
        initView();
    }

    private void initView() {
        withGlide().load(new GlideUrlModel(ApiConstantKt.getRemoteImageUrl()+imgId)).apply(GlideUtils.configDefaultRequestOptions()).into(ivShowImg);

        if (!PrefUtils.getIsFirstShowImg()) {
            ToastUtils.info("点击图片关闭页面");
            PrefUtils.setIsFirstShowImg(true);
        }

        ivShowImg.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
                ActivityStackManager.finish();
            }
        });
    }
}
